<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell @click="tiaoZhuanFn">
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ obj.title }}</span>
          <!-- 单图 -->
          <img
            class="thumb"
            v-if="obj.cover.type === 1"
            :src="obj.cover.images[0]"
          />
        </div>
        <!-- 三张图片 -->
        <div class="thumb-box" v-if="obj.cover.type > 1">
          <img
            v-for="(item, index) in obj.cover.images"
            :key="index"
            class="thumb"
            :src="item"
          />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>作者 {{ obj.aut_name }} </span>
            <span>&nbsp; {{ obj.comm_count }}评论 </span>
            <span> &nbsp;8个月前</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon name="cross" v-if="closeShow" @click="fanKuiFn" />
        </div>
      </template>
    </van-cell>
    <van-action-sheet
      v-model="show"
      :actions="actions"
      @select="onSelect"
      :cancel-text="quFan"
      get-container="body"
    />
  </div>
</template>

<script>
import { fanKuiOne, fanKuiTwo } from '@/api/fankui.js'
export default {
  data () {
    return {
      // 反馈面板是否开启
      show: false,
      // 反馈数据展示
      actions: fanKuiOne,
      // 取消 返回
      quFan: '取消'
    }
  },
  methods: {
    // 反馈事件  点击选项时触发，禁用或加载状态下不会触发
    onSelect (action, index) {
      // action 数据对象 index下标
      // console.log(action, index)
      if (action.name === '反馈垃圾内容') {
        // 切换二级数据
        this.actions = fanKuiTwo
        // this.quFan = '返回'
        this.show = true
      } else if (action.name === '不感兴趣') {
        this.$emit('shan', this.obj, action)
      } else if (action.name === '拉黑作者') {
        //
      } else if (action.name === '返回') {
        this.actions = fanKuiOne
      } else {
        this.$emit('shan', this.obj, action)
        this.show = false
      }
    },
    // 点击 x图标 开启反馈
    fanKuiFn () {
      this.show = true
    },
    // 点击二级返回选项,取消出现 ,一级数据出现
    onCancel () {
      // this.quFan = '取消'
      this.actions = fanKuiOne
      // this.show = true
    },
    // 点击页面跳转
    tiaoZhuanFn () {
      this.$router.push({
        path: `/article?id=${this.obj.art_id}`
        /**
         * path: '/article',
         * query: {
         *   id: this.obj.art_id
         * }
         */
      })
    }
  },
  props: {
    obj: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // 取消搜索页右下角的x号,但首页的x号保留
    closeShow: {
      type: Boolean,
      default: true
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
